package com.axzh.interview.problem;

public class Solution {

	public static int findMaxDifference(int[] arr, int len) {
		int[] result = new int[len];
		result[0] = 0;
		for (int i = 1; i < len; i++) {
			for (int j = i - 1; j >= 0; j--) {
				if (result[i] < (arr[i] - arr[j])) {
					result[i] = arr[i] - arr[j];
				}
			}
		}
		int max = result[0];
		for (int i = 0; i < len; i++) {
			if (max < result[i]) {
				max = result[i];
			}
		}
		return max;
	}

	public static void main(String[] args) {
		int[] arr = {5,10,3,11};
		System.out.println(findMaxDifference(arr, 4));
	}
}
